import json
import unittest
import requests
from parameterized import parameterized

from api.ihrm_login_api import IhrmLoginApi


def commmon_login():
    list_ihrm = []
    with open("data/ihrm_login.json", encoding="utf-8") as f:
        json_data = json.load(f)
        for i in json_data:
            tmp = tuple(i.values())
            list_ihrm.append(tmp)
        return list_ihrm

class TestIhrmLogin(unittest.TestCase):



    @parameterized.expand(commmon_login())
    def test01_login_success(self, a):
        resp = IhrmLoginApi.login(a)
        print(resp.json())

        self.assertEqual(200, resp.status_code)
        self.assertEqual(True, resp.json().get('success'))
        self.assertEqual(10000, resp.json().get('code'))
        self.assertEqual("登录成功", resp.json().get('message'))

    # def test02_login_success(self):
    #     resp = requests.post(url="https://heimahr.itheima.net/api/sys/login",
    #                          json={"mobile": "13800000002", "password": "hm#qd@23!"})
    #     print(resp.json())
    #
    #     self.assertEqual(200,resp.status_code)
    #     self.assertEqual(True,resp.json().get('success'))
    #     self.assertEqual(10000,resp.json().get('code'))
    #     self.assertEqual("登录成功",resp.json().get('message'))
